package com.yuzhi.fine.db.dao;

import android.content.Context;

import com.j256.ormlite.dao.Dao;
import com.yuzhi.fine.db.DatabaseHelper;
import com.yuzhi.fine.db.entity.User;
import com.yuzhi.fine.model.GanHuo;

import java.sql.SQLException;

/**
 * Created by Administrator on 2016/7/3.
 */
public class GanHuoDao {

    private Context context;
    private Dao<GanHuo, Integer> ganHuoDaoOpe;
    private DatabaseHelper helper;

    public GanHuoDao(Context context) {
        this.context = context;
        try {
            helper = DatabaseHelper.getHelper(context);
            ganHuoDaoOpe = helper.getDao(GanHuo.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * 增加一个用户
     *
     * @param user
     * @throws SQLException
     */
    public void add(GanHuo ganHuo) {
        /*//事务操作
		TransactionManager.callInTransaction(helper.getConnectionSource(),
				new Callable<Void>()
				{

					@Override
					public Void call() throws Exception
					{
						return null;
					}
				});*/
        try {
            ganHuoDaoOpe.create(ganHuo);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

    public GanHuo get(int id) {
        try {
            return ganHuoDaoOpe.queryForId(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
